package com.guigu.zj.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.SerialcodingMapper;
import com.guigu.mapper.YchecknapeMapper;
import com.guigu.pojo.Serialcoding;
import com.guigu.pojo.Ychecknape;
import com.guigu.zj.pojo.PageVo;
import com.guigu.zj.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class CheckServiceImpl implements CheckService {
    @Autowired
    YchecknapeMapper che;
    @Autowired
    SerialcodingMapper ser;
    public PageVo<Ychecknape> queryAll(PageVo pageVo) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getNum());
        List<Ychecknape> list = che.queryAll(pageVo);
        PageInfo pageInfo = new PageInfo(list);
        long total = pageInfo.getTotal();
        PageVo<Ychecknape> vo = new PageVo<Ychecknape>();
        vo.setTotal(total);
        vo.setRows(list);
        return vo;
    }

    public int insertSelective(Ychecknape record) {
        Serialcoding s = ser.find();
        record.setBh("jc00"+(s.getCheckupencoded()+1));
        Serialcoding serialcoding = new Serialcoding();
        serialcoding.setCheckupencoded(s.getCheckupencoded()+1);
        ser.update(serialcoding);
        return che.insertSelective(record);
    }

    public Ychecknape selectByPrimaryKey(Integer id) {
        return che.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Ychecknape record) {
        return che.updateByPrimaryKeySelective(record);
    }

    public int deleteByPrimaryKey(Integer id) {
        return che.deleteByPrimaryKey(id);
    }
}
